package ATM;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileReader;
import java.util.Properties;

public class ATMFrame extends JFrame {

    private int count;
    private MyJText inCount = new MyJText("用户名",130,60,this);
    private MyJText inPwd = new MyJText("密码",130,110,this);

    private Properties p = new Properties();


    public ATMFrame(){
        this.setLayout(null);

        MyButton button = new MyButton("登录",350,200,this);

        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                login();
            }
        });




        this.setSize(500,300);
        this.setVisible(true);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);

        try {
            p.load(new FileReader("Housework0906/src/ATM/ATM.txt"));
        }catch (Exception e){
            System.out.println("文件不存在");
        }
    }

    /**
     * 登录
     */
    private void login(){
        String count0 = p.getProperty("count");
        String pwd0 = p.getProperty("pwd");
        if (inCount.getText().equals(count0)&&inPwd.getText().equals(pwd0)){
            JOptionPane.showMessageDialog(null,"登录成功");

            this.dispose();
            new ItemFrame();
        }else {
            JOptionPane.showMessageDialog(null,"账号或密码有误，重新输入");
            this.count++;
        }
        if (count>=3){
            JOptionPane.showMessageDialog(null,"非法用户，账号冻结");
            System.exit(0);
        }
    }



    public static void main(String[] args) {
        new ATMFrame();
    }
}
